package za.co.EYEWTKAH.jmsProjects.openJmsPlugin;

import java.util.HashMap;
import java.util.Map;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import com.btmatthews.utils.monitor.Monitor;
import com.btmatthews.utils.monitor.Server;
import com.btmatthews.utils.monitor.ServerFactory;
import com.btmatthews.utils.monitor.mojo.AbstractRunMojo;

@Mojo(name = "run")
public class OpenJmsRunPlugin extends AbstractRunMojo  {
    
    @Parameter
    private String openJmsHome = "target/openJmsHome";

    @Parameter
    private Boolean createHome = true;
    
    private Map<String, Object> config = new HashMap<String, Object>();
    
    
    
    @Override
    public String getServerType() {

        return "openjms";
    }
    

    @Override
    public Map<String, Object> getServerConfig() {
  
        config.put("openJmsHome", openJmsHome);
        config.put("createHome", createHome);
        
        return config;
    }


    public void execute() throws MojoFailureException {

        // Create the server
        final ServerFactory factory = new OpenJmsServerFactory();
        final Server server = factory.createServer();

        // Configure the server

        final Map<String, Object> config = getServerConfig();
        for (final Map.Entry<String, Object> entry : config.entrySet()) {
            server.configure(entry.getKey(), entry.getValue(), this);
        }

        // Run the monitor

        final Monitor monitor = createMonitor();
        monitor.runMonitor(server, this, this);
    }
    
    
}
